package com.lzh.chatnote.chat.service.event.listener;

import com.lzh.chatnote.chat.service.event.MessageSendEvent;

import com.lzh.chatnote.common.constant.MQConstant;
import com.lzh.chatnote.common.mqProducer.MQProducer;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import javax.annotation.Resource;


@Slf4j
@Component
public class MessageSendListener {

    @Resource
    private MQProducer mqProducer;


    @TransactionalEventListener(classes = MessageSendEvent.class, phase = TransactionPhase.BEFORE_COMMIT, fallbackExecution = true)
    public void messagePushMQ(MessageSendEvent event) {
        mqProducer.sendMsg(MQConstant.SEND_MSG_TOPIC, event.getMsgId());
    }
}
